using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VKAZU
    {
        public DataRow Convert2KAZU(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKAZU(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KAZUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["KAZUDAT"] = " ".PadRight(8 ); 
         dwReturn["KAZUVB"] = " ".PadRight(3 ); 
         dwReturn["KAZUVG"] = " ".PadRight(3 ); 
         dwReturn["KAZUPROGRP"] = " ".PadRight(3 ); 
         dwReturn["KAZUARTGRP"] = " ".PadRight(3 ); 
         dwReturn["KAZUWR"] = " ".PadRight(2 ); 
         dwReturn["KAZULAND"] = " ".PadRight(3 ); 
         dwReturn["KAZUKOLL"] = " ".PadRight(5 ); 
         dwReturn["KAZUBRANCHE"] = " ".PadRight(3 ); 
         dwReturn["KAZUKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["KAZUVERBNR"] = " ".PadRight(8 ); 
         dwReturn["KAZUAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["KAZUAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["KAZUAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["KAZULKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["KAZUWERK"] = " ".PadRight(3 ); 
         dwReturn["KAZUABT"] = " ".PadRight(3 ); 
         dwReturn["KAZUWAKZ"] = " ".PadRight(1 ); 
         dwReturn["KAZUART"] = " ".PadRight(20 ); 
         dwReturn["KAZUVAR"] = " ".PadRight(2 ); 
         dwReturn["KAZUAENZL"] = " ".PadRight(0 ); 
         dwReturn["KAZUAENB"] = " ".PadRight(8 ); 
         dwReturn["KAZUAEND"] = " ".PadRight(0 ); 
         dwReturn["KAZUNEUB"] = " ".PadRight(8 ); 
         dwReturn["KAZUNEUD"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ1"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ2"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ3"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ4"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ5"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ6"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ7"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ8"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ9"] = " ".PadRight(0 ); 
         dwReturn["KAZUVVGKZ10"] = " ".PadRight(0 ); 
         dwReturn["KAZUVERPZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUVERSZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUFRAZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUZOLLZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUPROVZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUBONZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUSKTZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUEVZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUSEKSZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUSDBZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUZINSZ"] = " ".PadRight(0 ); 
         dwReturn["KAZUFILLER"] = " ".PadRight(91 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKAZU(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveKAZU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryKAZU(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapKAZU(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertKAZU(dwLocal, ITXDBVERSION);
            }
            UpdateKAZU(dwLocal);
        }
        public void InsertKAZU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO KAZU(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryKAZU(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KAZU WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM KAZU  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "KAZU";
            Return = Result;
            return Return;
        }
        public void DeleteKAZU(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KAZU   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateKAZU(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE KAZU SET "
                    +"KAZUMANDANT= :KAZUMANDANT,"
                    +"KAZUDAT= :KAZUDAT,"
                    +"KAZUVB= :KAZUVB,"
                    +"KAZUVG= :KAZUVG,"
                    +"KAZUPROGRP= :KAZUPROGRP,"
                    +"KAZUARTGRP= :KAZUARTGRP,"
                    +"KAZUWR= :KAZUWR,"
                    +"KAZULAND= :KAZULAND,"
                    +"KAZUKOLL= :KAZUKOLL,"
                    +"KAZUBRANCHE= :KAZUBRANCHE,"
                    +"KAZUKUNDNR= :KAZUKUNDNR,"
                    +"KAZUVERBNR= :KAZUVERBNR,"
                    +"KAZUAUFKRS= :KAZUAUFKRS,"
                    +"KAZUAUFLFD= :KAZUAUFLFD,"
                    +"KAZUAUFPOS= :KAZUAUFPOS,"
                    +"KAZULKUNDNR= :KAZULKUNDNR,"
                    +"KAZUWERK= :KAZUWERK,"
                    +"KAZUABT= :KAZUABT,"
                    +"KAZUWAKZ= :KAZUWAKZ,"
                    +"KAZUART= :KAZUART,"
                    +"KAZUVAR= :KAZUVAR,"
                    +"KAZUAENZL= :KAZUAENZL,"
                    +"KAZUAENB= :KAZUAENB,"
                    +"KAZUAEND= :KAZUAEND,"
                    +"KAZUNEUB= :KAZUNEUB,"
                    +"KAZUNEUD= :KAZUNEUD,"
                    +"KAZUVVGKZ1= :KAZUVVGKZ1,"
                    +"KAZUVVGKZ2= :KAZUVVGKZ2,"
                    +"KAZUVVGKZ3= :KAZUVVGKZ3,"
                    +"KAZUVVGKZ4= :KAZUVVGKZ4,"
                    +"KAZUVVGKZ5= :KAZUVVGKZ5,"
                    +"KAZUVVGKZ6= :KAZUVVGKZ6,"
                    +"KAZUVVGKZ7= :KAZUVVGKZ7,"
                    +"KAZUVVGKZ8= :KAZUVVGKZ8,"
                    +"KAZUVVGKZ9= :KAZUVVGKZ9,"
                    +"KAZUVVGKZ10= :KAZUVVGKZ10,"
                    +"KAZUVERPZ= :KAZUVERPZ,"
                    +"KAZUVERSZ= :KAZUVERSZ,"
                    +"KAZUFRAZ= :KAZUFRAZ,"
                    +"KAZUZOLLZ= :KAZUZOLLZ,"
                    +"KAZUPROVZ= :KAZUPROVZ,"
                    +"KAZUBONZ= :KAZUBONZ,"
                    +"KAZUSKTZ= :KAZUSKTZ,"
                    +"KAZUEVZ= :KAZUEVZ,"
                    +"KAZUSEKSZ= :KAZUSEKSZ,"
                    +"KAZUSDBZ= :KAZUSDBZ,"
                    +"KAZUZINSZ= :KAZUZINSZ,"
                    +"KAZUFILLER= :KAZUFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KAZUMANDANT", OracleType.NVarChar).Value = dwData["KAZUMANDANT"].ToString(); 
          or1.Parameters.Add("KAZUDAT", OracleType.NVarChar).Value = dwData["KAZUDAT"].ToString(); 
          or1.Parameters.Add("KAZUVB", OracleType.NVarChar).Value = dwData["KAZUVB"].ToString(); 
          or1.Parameters.Add("KAZUVG", OracleType.NVarChar).Value = dwData["KAZUVG"].ToString(); 
          or1.Parameters.Add("KAZUPROGRP", OracleType.NVarChar).Value = dwData["KAZUPROGRP"].ToString(); 
          or1.Parameters.Add("KAZUARTGRP", OracleType.NVarChar).Value = dwData["KAZUARTGRP"].ToString(); 
          or1.Parameters.Add("KAZUWR", OracleType.NVarChar).Value = dwData["KAZUWR"].ToString(); 
          or1.Parameters.Add("KAZULAND", OracleType.NVarChar).Value = dwData["KAZULAND"].ToString(); 
          or1.Parameters.Add("KAZUKOLL", OracleType.NVarChar).Value = dwData["KAZUKOLL"].ToString(); 
          or1.Parameters.Add("KAZUBRANCHE", OracleType.NVarChar).Value = dwData["KAZUBRANCHE"].ToString(); 
          or1.Parameters.Add("KAZUKUNDNR", OracleType.NVarChar).Value = dwData["KAZUKUNDNR"].ToString(); 
          or1.Parameters.Add("KAZUVERBNR", OracleType.NVarChar).Value = dwData["KAZUVERBNR"].ToString(); 
          or1.Parameters.Add("KAZUAUFKRS", OracleType.NVarChar).Value = dwData["KAZUAUFKRS"].ToString(); 
          or1.Parameters.Add("KAZUAUFLFD", OracleType.NVarChar).Value = dwData["KAZUAUFLFD"].ToString(); 
          or1.Parameters.Add("KAZUAUFPOS", OracleType.NVarChar).Value = dwData["KAZUAUFPOS"].ToString(); 
          or1.Parameters.Add("KAZULKUNDNR", OracleType.NVarChar).Value = dwData["KAZULKUNDNR"].ToString(); 
          or1.Parameters.Add("KAZUWERK", OracleType.NVarChar).Value = dwData["KAZUWERK"].ToString(); 
          or1.Parameters.Add("KAZUABT", OracleType.NVarChar).Value = dwData["KAZUABT"].ToString(); 
          or1.Parameters.Add("KAZUWAKZ", OracleType.NVarChar).Value = dwData["KAZUWAKZ"].ToString(); 
          or1.Parameters.Add("KAZUART", OracleType.NVarChar).Value = dwData["KAZUART"].ToString(); 
          or1.Parameters.Add("KAZUVAR", OracleType.NVarChar).Value = dwData["KAZUVAR"].ToString(); 
          or1.Parameters.Add("KAZUAENZL", OracleType.NVarChar).Value = dwData["KAZUAENZL"].ToString(); 
          or1.Parameters.Add("KAZUAENB", OracleType.NVarChar).Value = dwData["KAZUAENB"].ToString(); 
          or1.Parameters.Add("KAZUAEND", OracleType.NVarChar).Value = dwData["KAZUAEND"].ToString(); 
          or1.Parameters.Add("KAZUNEUB", OracleType.NVarChar).Value = dwData["KAZUNEUB"].ToString(); 
          or1.Parameters.Add("KAZUNEUD", OracleType.NVarChar).Value = dwData["KAZUNEUD"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ1", OracleType.NVarChar).Value = dwData["KAZUVVGKZ1"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ2", OracleType.NVarChar).Value = dwData["KAZUVVGKZ2"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ3", OracleType.NVarChar).Value = dwData["KAZUVVGKZ3"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ4", OracleType.NVarChar).Value = dwData["KAZUVVGKZ4"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ5", OracleType.NVarChar).Value = dwData["KAZUVVGKZ5"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ6", OracleType.NVarChar).Value = dwData["KAZUVVGKZ6"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ7", OracleType.NVarChar).Value = dwData["KAZUVVGKZ7"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ8", OracleType.NVarChar).Value = dwData["KAZUVVGKZ8"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ9", OracleType.NVarChar).Value = dwData["KAZUVVGKZ9"].ToString(); 
          or1.Parameters.Add("KAZUVVGKZ10", OracleType.NVarChar).Value = dwData["KAZUVVGKZ10"].ToString(); 
          or1.Parameters.Add("KAZUVERPZ", OracleType.NVarChar).Value = dwData["KAZUVERPZ"].ToString(); 
          or1.Parameters.Add("KAZUVERSZ", OracleType.NVarChar).Value = dwData["KAZUVERSZ"].ToString(); 
          or1.Parameters.Add("KAZUFRAZ", OracleType.NVarChar).Value = dwData["KAZUFRAZ"].ToString(); 
          or1.Parameters.Add("KAZUZOLLZ", OracleType.NVarChar).Value = dwData["KAZUZOLLZ"].ToString(); 
          or1.Parameters.Add("KAZUPROVZ", OracleType.NVarChar).Value = dwData["KAZUPROVZ"].ToString(); 
          or1.Parameters.Add("KAZUBONZ", OracleType.NVarChar).Value = dwData["KAZUBONZ"].ToString(); 
          or1.Parameters.Add("KAZUSKTZ", OracleType.NVarChar).Value = dwData["KAZUSKTZ"].ToString(); 
          or1.Parameters.Add("KAZUEVZ", OracleType.NVarChar).Value = dwData["KAZUEVZ"].ToString(); 
          or1.Parameters.Add("KAZUSEKSZ", OracleType.NVarChar).Value = dwData["KAZUSEKSZ"].ToString(); 
          or1.Parameters.Add("KAZUSDBZ", OracleType.NVarChar).Value = dwData["KAZUSDBZ"].ToString(); 
          or1.Parameters.Add("KAZUZINSZ", OracleType.NVarChar).Value = dwData["KAZUZINSZ"].ToString(); 
          or1.Parameters.Add("KAZUFILLER", OracleType.NVarChar).Value = dwData["KAZUFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
